package com.splider.toutiao;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;

public class QuTouTiaoSplider {
	
	private static String[] categorys = {"all"};
	
	private static Logger logger = Logger.getLogger("toutiao");
	
//	private static ThreadPoolExecutor executor = null;
	
	public static void main(String[] args) {
		String thread = ApplicationConfig.prop.getProperty("thread_size", "5");
		int thread_size = 5;
		try {
			thread_size = Integer.parseInt(thread);
		} catch (Exception e) {
		}
		logger.info("线程数:"+thread_size);
		ExecutorService executor = Executors.newFixedThreadPool(thread_size);
		int resultdata[] = new int[categorys.length];
		List<Integer> dataArray = new ArrayList<Integer>();
		for (int i = 0; i < categorys.length; i++) {
			dataArray.add(i);
		}
		int i = 0;
		while (dataArray.size() > 0) {
			int index = (int) (Math.random() * dataArray.size());
			resultdata[i] = dataArray.get(index);
			i++;
			dataArray.remove(index);
		}
		List<ProxyIP> proxyIps = new ArrayList<ProxyIP>();
		if("1".equals(ApplicationConfig.prop.getProperty("useProxy_taojin"))
				||"1".equals(ApplicationConfig.prop.getProperty("useProxy_toutiao"))){
			proxyIps = new CommonUtils().getProxyIPList();
		}
		for (int j = 0; j < resultdata.length; j++) {
			executor.execute(new QuTouTiaoTask(categorys[resultdata[j]], proxyIps));
		}
		executor.shutdown();
	}
}
